package com.voute.Presenter.Impl;

import android.content.Context;

import com.voute.Model.Bean.BaseBean;
import com.voute.Model.Bean.CircleDetailsInfoBean;
import com.voute.Model.Bean.DiscoveryBean;
import com.voute.Model.ICircleModel;
import com.voute.Model.Impl.CircleModelImpl;
import com.voute.Presenter.ICircleDetailsPresenter;
import com.voute.Utils.CommonSubscriber;
import com.voute.Utils.TransformUtils;
import com.voute.View.IView.ICircleView;

/**
 * Created by liucxu on 2017/4/27.
 */

public class CircleDetailPresenterImpl implements ICircleDetailsPresenter {

    private ICircleView circleView;
    private Context mContext;

    private ICircleModel model;

    public CircleDetailPresenterImpl(Context c, ICircleView v) {
        circleView = v;
        mContext = c;
        model = new CircleModelImpl();
    }

    @Override
    public void requestCircleDetails(String hash_circle, String anchor) {
        model.requestCircleDetails(hash_circle, anchor).compose(TransformUtils.<DiscoveryBean>defaultSchedulers()).subscribe(new CommonSubscriber<DiscoveryBean>() {
            @Override
            public void onSuccess(DiscoveryBean response) {
                circleView.hideLoading();
                circleView.refreshCircleDetailsView(response);
            }

            @Override
            public void onFailure(BaseBean response) {
                circleView.hideLoading();
                circleView.showError(response.getMsg());
            }
        });
    }

    @Override
    public void requestCircleBaseInfo(String hash_circle) {
        model.requestCircleBaseInfo(hash_circle).compose(TransformUtils.<CircleDetailsInfoBean>defaultSchedulers()).subscribe(new CommonSubscriber<CircleDetailsInfoBean>() {
            @Override
            public void onSuccess(CircleDetailsInfoBean response) {
                circleView.setCircleBaseInfo(response);
            }

            @Override
            public void onFailure(BaseBean response) {
                circleView.showError(response.getMsg());
            }
        });
    }

    @Override
    public void JoinCircle(String hash_circle) {
        model.JoinCircle(hash_circle).compose(TransformUtils.<BaseBean>defaultSchedulers()).subscribe(new CommonSubscriber<BaseBean>() {
            @Override
            public void onSuccess(BaseBean response) {
                circleView.joinCircleSuccess();
            }

            @Override
            public void onFailure(BaseBean response) {
                circleView.showError(response.getMsg());
            }
        });
    }

    @Override
    public void ExitCircle(String hash_circle) {
        model.ExitCircle(hash_circle).compose(TransformUtils.<BaseBean>defaultSchedulers()).subscribe(new CommonSubscriber<BaseBean>() {
            @Override
            public void onSuccess(BaseBean response) {
                circleView.exitCircleSuccess();
            }

            @Override
            public void onFailure(BaseBean response) {
                circleView.showError(response.getMsg());
            }
        });
    }
}
